const api = require("../../../utils/api")

var e = getApp(),
  a = require("../../../utils/qqmap-wx-jssdk.min.js"),
  i = require("../../../utils/sensorsdata.min.js"),
  s = void 0;

Page({
  data: {
    faver: [],
    userInfo: {},
    hasUserInfo: !1,
    canIUse: wx.canIUse("button.open-type.getUserInfo"),
    sessionKey: "",
    uid: "",
    act: 1,
    show_tab_bar: !0,
    page_index: "dsj",
    layer: !0,
    flag: !0,
    region: [{
      letters: "B",
      regionInfo: ["滨州"]
    }, {
      letters: "D",
      regionInfo: ["德州", "东营"]
    }, {
      letters: "H",
      regionInfo: ["菏泽"]
    }, {
      letters: "J",
      regionInfo: ["济南", "济宁"]
    }, {
      letters: "L",
      regionInfo: ["临沂", "聊城"]
    }, {
      letters: "Q",
      regionInfo: ["青岛"]
    }, {
      letters: "S",
      regionInfo: ["省属"]
    }, {
      letters: "W",
      regionInfo: ["潍坊", "威海"]
    }, {
      letters: "T",
      regionInfo: ["泰安"]
    }, {
      letters: "R",
      regionInfo: ["日照"]
    }, {
      letters: "Y",
      regionInfo: ["烟台"]
    }, {
      letters: "Z",
      regionInfo: ["淄博", "枣庄"]
    }],
    scrollHeight: wx.getSystemInfoSync().windowHeight - 140,
    location: "省属",
    top: null,
    lock: !0,
    shadow: !1,
    showJob: !1,
    job: "机关单位",
    jobIndex: null,
    showJmfs: !1,
    jmfs: "进面分数",
    showTgrs: !1,
    tgrs: "通过人数",
    jmfsIndex: null,
    jmfsList: ["由高到低", "由低到高", "研究生"],
    showYear: !1,
    year: "2022",
    yearIndex: null,
    yearList: ["2018", "2019", "2020", "2021", "2022"],
    showMajor: !1,
    major: "专业",
    majorIndex: null,
    majorList: null,
    showMore: !1,
    sort: null,
    jidActive01: 0,
    jidActive02: 0,
    jidActive03: 0,
    midActive01: 0,
    midActive02: 0,
    midActive03: 0,
    zwk_diqu: "",
    zwk_fenlei: "",
    zwk_yrsj: "",
    keyword: "",
    xueli: "",
    xuewei: "",
    zwk_bmmc: "",
    zhuanye: "",
    page: "1",
    zwk_jcnx: "",
    zwk_zzmm: "",
    zwk_zyks: "",
    zknum: "",
    is_tiaoji: 0,
    zwk_xitong: "",
    zwk_zwmj: "",
    zwk_zhiweidaima: "",
    leixing: "",
    orderway: "desc",
    list: [],
    jcnxList: ["不限", "一年", "二年", "三年", "五年及以上"],
    zzmmList: ["不限", "共青团员", "中共党员"],
    zhunayeList: ["是", "否"],
    xwList: ["无要求", "学士", "硕士", "博士", "与最高学历相对应的学位"],
    collectNum: 0,
    barGoBack: !1,
    goZy: 0,
    jobArr: [],
    majorArr: [],
    channel: ""
  },
  go_jobInfo: function (t) {
    var z = t.currentTarget.dataset.zdy
    wx.navigateTo({
      url: "../../search/jobInfo/jobInfo?zdy=" + z
    })

  },
  addJob: function (t) {
    const phone = wx.getStorageSync('51488phone');
    var _ = this,
      i = t.currentTarget.dataset.id,
      s = this.data.list,
      o = t.currentTarget.dataset.index;
    console.log(s[o])
    if (phone) {
      wx.request({
        url: 'https://zg99.offcn.com/index/chaxun/writelogs?actid=51488&callback=?',
        data: {
          phone: wx.getStorageSync('51488phone'),
          nf: s[o].nianfen,
          zwmc: s[o].zhiweimingcheng,
          bmmc: s[o].zhaolujiguan,
          zlsl: s[o].luyongjihua,
          msbl: s[o].wuritongguo,
          zzmm: s[o].zhengzhimianmao,
          bz: s[o].beizhu,
          zwdm: s[o].zhiweidaima,
          zdy: i,
          sstimes: new Date().getTime(),
        },
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson);
          if (theJson.status == 1) {
            wx.showToast({
              title: '添加成功！',
              icon: 'none',
              duration: 2000
            })
          } else {
            wx.showToast({
              title: '请勿重复添加！',
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    } else {

      wx.showModal({
        title: '登陆之后使用收藏功能,前往登陆吗？',
        success(res) {
          if (res.cancel) {

          } else if (res.confirm) {
            wx.navigateTo({
              url: '../../login/login',
            })
          }
        }
      })

    }

  },
  jmfsD2G: function () {
    var _ = this;
    console.log()
    var arr = _.data.list
    console.log(arr)
    var brr = arr.sort(_.compare("zongchengjizuidifen", true));
    console.log(brr)

    _.setData({
      list: brr,
      lock: !0,
      showJmfs: !1,
      shadow: !1,
    })
  },
  jmfsG2D: function () {
    var _ = this;
    console.log()
    var arr = _.data.list
    console.log(arr)
    var brr = arr.sort(_.compare("zongchengjizuidifen", false));
    console.log(brr)
    _.setData({
      list: brr,
      lock: !0,
      showJmfs: !1,
      shadow: !1
    })
  },
  tgrsD2G: function () {
    var _ = this;
    console.log('1')
    var arr = _.data.list
    console.log(arr)
    var brr
    var year = arr[0].year;
    if (year == 2021) {
      brr = arr.sort(_.compare1("siritongguo", true));
    } else if (year == 2020) {
      brr = arr.sort(_.compare1("liuritongguo", true));
    } else {
      brr = arr.sort(_.compare1("wuritongguo", true));
    }
    _.setData({
      list: brr,
      lock: !0,
      showTgrs: !1,
      shadow: !1,
    })
  },
  tgrsG2D: function () {
    var _ = this;
    console.log('2')
    var arr = _.data.list
    console.log(arr[0].year)
    var year = arr[0].year;
    if (year == 2021) {
      var brr = arr.sort(_.compare1("siritongguo", false));
    } else if (year == 2020) {
      var brr = arr.sort(_.compare1("liuritongguo", false));
    } else {
      var brr = arr.sort(_.compare1("wuritongguo", false));
    }

    console.log(brr)
    _.setData({
      list: brr,
      lock: !0,
      showTgrs: !1,
      shadow: !1
    })
  },

  onShow: function () {

  },
  onLoad: function (o) {
    var n = this,
      r = this;


    wx.request({
      url: "https://zg99.offcn.com/index/chaxun/getfylist/?actid=51488&callback=?",
      method: "get",
      data: {
        phone: '15205451183',
        year: 2022,
        page: 1,
        dishi: '济南',
        limits: 20,
      },
      success: function (e) {
        var jsonStr = e.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)
        n.setData({
          list: theJson.lists
        })
      },


    });

    if (o.channel && (i.registerApp({
        data_source: o.channel
      }), this.setData({
        channel: o.channel
      })), s = new a({
        key: "Z3HBZ-VX3CP-PQVDI-LMW43-7PQB6-SWFFE"
      }), wx.getLocation({
        type: "wgs84",
        isHighAccuracy: !0,
        success: function (t) {
          console.log(t)
          wx.setStorageSync("latitude", t.latitude), wx.setStorageSync("longitude", t.longitude),
            r.getLocal(t.latitude, t.longitude), i.registerApp({
              $latitude: wx.getStorageSync("latitude") ? 1e6 * wx.getStorageSync("latitude") : "",
              $longitude: wx.getStorageSync("longitude") ? 1e6 * wx.getStorageSync("longitude") : ""
            });
        },
        fail: function () {
          wx.getStorageSync("pos_choose") || (r.setData({
            location: "济南"
          }), wx.setStorageSync("city", "济南"));
        }
      }), 1 == o.is_tiaoji && this.setData({
        is_tiaoji: 1,
        tiaoji: !0
      }), o.zwk_diqu) {
      var d;
      this.setData((d = {
        zwk_sheng: o.zwk_sheng,
        zwk_diqu: o.zwk_diqu,
        zwk_bmmc: o.zwk_bmmc,
        zwk_zwmj: o.zwk_zwmj,
        zwk_zhiweidaima: o.zwk_zhiweidaima
      }, t(d, "zwk_sheng", o.zwk_sheng), t(d, "goZy", 1), d));
    }

  },
  gologin: function () {
    api.showToastNone('请先登录')
    wx.navigateTo({
      url: '../../login/login',
    })
  },

  compare: function (property, desc) {
    return function (a, b) {
      var value1 = a[property];
      var value2 = b[property];
      if (desc == true) {
        // 升序排列
        return value1 - value2;
      } else {
        // 降序排列
        return value2 - value1;
      }
    }
  },
  compare1: function (property, desc) {
    return function (a, b) {
      var value1 = a[property].replace("+", "");
      var value2 = b[property].replace("+", "");
      if (desc == true) {
        // 升序排列
        if (value1 == '3-') {
          value1 = 2
        } else if (value2 == '3-') {
          value2 = 2
        }
        return value1 - value2;
      } else {
        // 降序排列
        return value2 - value1;
      }
    }
  },
  getList: function (t) {
    var a = this;
    var phone = wx.getStorageSync('phone')
    console.log(phone)
    if (1 != this.data.flag) return !1;
    this.setData({
      flag: !1
    }), this.data.success && wx.showLoading({
      title: "加载中"
    }), wx.request({
      url: "https://zg99.offcn.com/index/chaxun/getfylist/?actid=51488&callback=?",
      method: "get",
      data: {
        phone: wx.getStorageSync('phone'),
        year: a.data.year,
        page: a.data.page,
        gongzuodidian: a.data.location,
        limits: 20,
      },
      success: function (e) {
        var jsonStr = e.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)

        if (theJson.status == 1) {
          t ? a.setData({
            list: a.data.list.concat(theJson.lists)
          }) : a.setData({
            list: theJson.lists
          }), 1 == theJson.status ? a.setData({
            page: Number(theJson.page),
            total: theJson.zcounts,
          }) : 2 == theJson.status && a.setData({
            msg: theJson.msg,
          })
        } else {
          // wx.showToast({
          //     title: '暂无此职位数据',
          // })
        }




      },
      fail: function () {
        a.data.success && wx.hideLoading(), a.setData({
          flag: !0,
          success: !0
        });
      },
      complete: function () {
        a.data.success && wx.hideLoading(), a.setData({
          flag: !0,
          success: !0
        });
      }
    });
  },
  lower: function () {
    1 != this.data.over && (this.setData({
      page: this.data.page + 1,
      flag: !0
    }), this.getList(!0));
  },
  changeRegion: function () {
    this.setData({
      layer: !1,
      show_tab_bar: !1
    }), this.closeLayer();
  },
  transfer: function (t) {
    var e = t.currentTarget.dataset.letter;
    this.setData({
      toView: e
    });
  },
  replaceRegion: function (t) {
    var e = t.currentTarget.dataset.value;
    // if ("澳门" == e || "香港" == e || "台湾" == e) return wx.showToast({
    //     title: "该地区没有数据，请换个地区吧~",
    //     icon: "none"
    // }), !1;
    this.setData({
        location: e,
        layer: !0,
        zwk_sheng: wx.setStorageSync("city", e)
      }), wx.setStorageSync("pos_choose", "true"), this.getList(),
      this.setData({
        scrollTop: 95,
        show_tab_bar: !0
      });
  },
  closeProvSelect: function () {
    this.setData({
      layer: !0,
      show_tab_bar: !0
    });
  },
  onShareAppMessage: function () {
    return {
      title: "省考小助手",
      path: "/pages/index/index"
    };
  },
  closeLayer: function () {
    this.setData({
      lock: !0,
      shadow: !1,
      showJob: !1,
      showJmfs: !1,
      showTgrs: !1,
      showYear: !1,
      showMajor: !1,
      showMore: !1,
      fixedbar: !1
    });
  },
  bindJmfs: function () {
    if (this.data.showJmfs) return this.setData({
      showJmfs: !1,
      shadow: !1,
      top: "top",
      lock: !0
    }), this.data.list.length < 1 && this.setData({
      fixedbar: !1
    }), !1;
    this.setData({
      shadow: !0,
      showJmfs: !0,
      showTgrs: !1,
      showYear: !1,
      showMore: !1,
      top: "top",
      lock: !1,
      fixedbar: !0
    });
  },
  choose_jmfs: function (t) {
    var e = t.currentTarget.dataset.text,
      a = t.currentTarget.dataset.index;
    console.log(e)
    console.log(a)

    this.setData({
      jmfsIndex: a,
      xueli: e,
      jmfs: e
    }), this.setData({
      lock: !0,
      showJmfs: !1,
      shadow: !1
    }), this.setData({
      scrollTop: 95
    }), this.getList();
  },
  bindTgrs: function () {
    if (this.data.showTgrs) return this.setData({
      showTgrs: !1,
      shadow: !1,
      top: "top",
      lock: !0
    }), this.data.list.length < 1 && this.setData({
      fixedbar: !1
    }), !1;
    this.setData({
      shadow: !0,
      showTgrs: !0,
      showJmfs: !1,
      showYear: !1,
      showMore: !1,
      top: "top",
      lock: !1,
      fixedbar: !0
    });
  },
  choose_tgrs: function (t) {
    var e = t.currentTarget.dataset.text,
      a = t.currentTarget.dataset.index;
    console.log(e)
    console.log(a)

    this.setData({
      jmfsIndex1: a,
      xueli: e,
      tgrs: e
    }), this.setData({
      lock: !0,
      showTgrs: !1,
      shadow: !1
    }), this.setData({
      scrollTop: 95
    }), this.getList();
  },

  bindYear: function () {
    if (this.data.showYear) return this.setData({
      showYear: !1,
      shadow: !1,
      top: "top",
      lock: !0
    }), this.data.list.length < 1 && this.setData({
      fixedbar: !1
    }), !1;
    this.setData({
      shadow: !0,
      showYear: !0,
      showJmfs: !1,
      showTgrs: !1,
      showMore: !1,
      top: "top",
      lock: !1,
      fixedbar: !0
    });
  },
  choose_year: function (t) {
    var e = t.currentTarget.dataset.text,
      a = t.currentTarget.dataset.index;
    console.log(e)
    console.log(a)

    this.setData({
      yearIndex: a,
      year: e
    }), this.setData({
      lock: !0,
      showYear: !1,
      shadow: !1
    }), this.setData({
      scrollTop: 95
    }), this.getList();
  },

  backTop: function () {
    this.setData({
      scrollTop: 0
    });
  },
  barGoBack: function (t) {
    this.backTop();
  },
  getLocal: function (t, e) {
    var a = this;
    s.reverseGeocoder({
      location: {
        latitude: t,
        longitude: e
      },
      success: function (t) {
        var e = t.result.ad_info.province.replace("市", ""),
          i = t.result.ad_info.city.replace("市", "");
        e = (e = (e = (e = (e = (e = e.replace("省", "")).replace("壮族自治区", "")).replace("回族自治区", "")).replace("维吾尔自治区", "")).replace("自治区", "")).replace("特别行政区", ""),
          console.log(e);
        console.log(i);
        if (e != '山东') {
          a.setData({
            location: '省属'
          });
        } else {
          wx.setStorageSync("position", e), wx.setStorageSync("city", i), a.setData({
            location: i
          });
        }

      },
      fail: function (t) {
        console.log(t);
      }
    });
  },

});